<?php
if (!defined('BASEPATH')) {
    exit('No direct script access allowed');
}

class Page_m extends FOX_Model
{

    function __construct()
    {
        parent::__construct();
    }

    /**
     * @param $good_id
     * @return mixed
     * 查询单条
     */
    public function get_all_pages($limit, $start)
    {

        $this->db->select('*');
        $this->db->from('pages');
        $this->db->limit($start, $limit);
        $query = $this->db->get();
        return $query->result_array();
    }

    //添加资讯
    public function add_pages($data)
    {
        $this->db->insert('pages', $data);
        if ($this->db->affected_rows() > 0) {
            return $this->db->insert_id();
        } else {
            return false;
        }
    }

    // 修改资讯

    public function save_pages($pages_id, $data)
    {
        $this->db->where('id', $pages_id);
        $this->db->update('pages', $data);
        return ($this->db->affected_rows() > 0) ? true : false;
    }

    public function get_pages_by_id($pages_id)
    {
        $this->db->select('*');
        $this->db->from('pages');
        $this->db->where('id', $pages_id);
        $query = $this->db->get();
        return $query->row_array();
    }

    //删除文章
    public function del_pages($id)
    {
        $this->db->where('id', $id)->delete('pages');
    }

    public function get_pages()
    {
        $this->db->select('*');
        $this->db->from('pages');
        $this->db->order_by('id', "desc");
        $this->db->limit(10);
        $query = $this->db->get();
        return $query->result_array();
    }

    public function get_pages_by_uid($uid, $type)
    {
        $this->db->select('*');
        $this->db->from('pages');
        $this->db->where('user_id', $uid);
        $this->db->where('type', $type);
        $this->db->order_by('id', "desc");
        $query = $this->db->get();
        return $query->row_array();
    }
}
